package com.changgou.goods.controller;
import com.changgou.entity.PageResult;
import com.changgou.entity.Result;
import com.changgou.entity.StatusCode;
import com.changgou.goods.service.ParaService;
import com.changgou.goods.pojo.Para;
import com.github.pagehelper.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;
@RestController
@CrossOrigin
@RequestMapping("/para")
public class ParaController {


    @Autowired
    private ParaService paraService;


    /*
    添加规格列表
     */
    @PostMapping("/add")
    public Result add(@RequestBody Para para){
        paraService.add(para);
        return new Result(true, StatusCode.OK,"规格列表添加成功");
    }
    /*
    删除规格列表
     */
    @GetMapping("/delete/{id}")
    public Result delete(@PathVariable(value = "id") int id){
        paraService.delete(id);
        return new Result(true, StatusCode.OK,"规格列表删除成功");
    }
    /*
    规格列表分页查询
     */
    @GetMapping("/findpage/{page}/{size}")
    public PageResult findall(@PathVariable(value = "page") int page,@PathVariable(value = "size") int size){
        Page<Para> list = paraService.findall(page,size);
        return new PageResult<>(list.getTotal(),list.getResult());
    }

    /**
     * 根据模板id查询参数信息
     * @return
     */
    @GetMapping("{id}")
    public Result findParaByTemId(@PathVariable int id){
        List<Para> paraList = paraService.findParaByTemId(id);
        return new Result(true, StatusCode.OK,"查询成功",paraList);
    }

}
